package com.vincent.javacourse.controller;


import com.vincent.javacourse.entity.Teacher;
import com.vincent.javacourse.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-12-24
 */
@RestController
@RequestMapping("//teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/list")
    private List<Teacher> list() {
        return this.teacherService.list();
    }

    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id) {
        return this.teacherService.removeById(id);
    }

    @GetMapping("/find/{id}")
    public Teacher find(@PathVariable("id") Integer id) {
        return this.teacherService.getById(id);
    }

    @PostMapping("/add")
    public boolean add(@RequestBody Teacher teacher) {
        return this.teacherService.save(teacher);
    }

    @PostMapping("/create")
    public Map<String, Object> createTeacher(@RequestBody Teacher teacher) {
        return teacherService.createTeacher(teacher);
    }

    @PostMapping("/login")
    public Map<String, Object> loginTeacher(@RequestBody Teacher teacher) {
        return teacherService.loginTeacher(teacher);
    }


    /*
    @PutMapping("/update")
    public boolean update(@RequestBody Teacher teacher) {
        return this.teacherService.updateById(teacher);
    }

     */
    @PutMapping("/update")
    public Map<String, Object> updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateTeacher(teacher);
    }
}

